using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;

namespace NotifyDrink
{
    public partial class Form1 : Form
    {
        private Timer timer = new Timer();
        private Timer timer2 = new Timer();


        public Form1()
        {
            InitializeComponent();
            InitUI();
        }

        private void InitUI()
        {
            timer.Tick += (sender, args) => ReActiveWindow();
            timer.Interval = 3600000;
            timer.Start();

            timer2.Tick += (sender, args) => MinimizeWindow();
            timer2.Interval = 5000;

            FormClosing += OnFormClosing;
            exitToolStripMenuItem.Click += (sender, args) => { Dispose(); Close(); };
            //            notifyIcon1.Visible = true;
            notifyIcon1.MouseDoubleClick += (sender, args) => { ReActiveWindow(); };
            //            ControlBox = false;
            //            MaximizeBox = false;
            //            MinimizeBox = false;
            //            WindowState = FormWindowState.Maximized;
            //            FormBorderStyle = FormBorderStyle.None;
            //            ControlBox = false;
            //            SizeChanged += OnSizeChanged;
            //不在系统任务栏显示主窗口图标
            ShowInTaskbar = false;
            MinimizeWindow();
        }


        private void OnFormClosing(object sender, FormClosingEventArgs e)
        {
            //            取消关闭窗口
            e.Cancel = true;
            MinimizeWindow();
        }

        private void MinimizeWindow()
        {
            //最小化主窗口
            Visible = false;
            WindowState = FormWindowState.Minimized;
            //            notifyIcon1.Visible = true;
            timer2.Stop();
        }

        private void ReActiveWindow()
        {
            if (WindowState == FormWindowState.Minimized)
            {
                Visible = true;
                //还原窗体显示    
                WindowState = FormWindowState.Normal;
                //激活窗体并给予它焦点
                Activate();
                //                notifyIcon1.Visible = false;
                timer2.Start();
            }
        }

    }
}
